﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class QuanTri_QuanLyCanBoGiaoVen : System.Web.UI.Page
{
    SoLienLacDataContext db = new SoLienLacDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] == null || Session["Username"].ToString() == "")
        {
            Response.Redirect("~/GiaoDienClient/TrangChu.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                LoadLenGridView();
            }
        }
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        Response.Redirect("~QuanTri/NhapTTGV.aspx");
    }
    void LoadLenGridView()
    {
        var c = from p in db.CanBoGiaoViens select p;
        grvDanhSachGV.DataSource = c;
        grvDanhSachGV.DataBind();
    }
    protected void grvDanhSachGV_RowEditing(object sender, GridViewEditEventArgs e)
    {

        Label MaGV = (Label)grvDanhSachGV.Rows[e.NewEditIndex].Cells[1].FindControl("lblMaGV");
        TextBox GV = (TextBox)grvDanhSachGV.Rows[e.NewEditIndex].Cells[1].FindControl("txtTenGV");
        DropDownList drGioiTinh = (DropDownList)grvDanhSachGV.Rows[e.NewEditIndex].Cells[3].FindControl("ddlGioiTinh");
        TextBox NgaySinh = (TextBox)grvDanhSachGV.Rows[e.NewEditIndex].Cells[2].FindControl("txtNgaySinh");
        //NgaySinh.Text = DateTime.Now.ToShortDateString();
        TextBox txtMail = (TextBox)grvDanhSachGV.Rows[e.NewEditIndex].Cells[5].FindControl("txtEmail");
        TextBox SDT = (TextBox)grvDanhSachGV.Rows[e.NewEditIndex].Cells[6].FindControl("txtSDT");
        TextBox DiaChi = (TextBox)grvDanhSachGV.Rows[e.NewEditIndex].Cells[4].FindControl("txtDiaChi");
        CanBoGiaoVien cb = db.CanBoGiaoViens.SingleOrDefault(p => p.MaCanBoGV == MaGV.Text);
        MaGV.Text = cb.MaCanBoGV;
        GV.Text = cb.TenCanBo;
        NgaySinh.Text = cb.NgaySinh.ToString();
        txtMail.Text = cb.Email;
        SDT.Text = cb.SDT;
        DiaChi.Text = cb.DiaChi;
        drGioiTinh.SelectedItem.Text = cb.GioiTinh;
        db.SubmitChanges();
    }
}
